print("scan Trade Requests toggle start")

local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local lp = Players.LocalPlayer
if not lp then repeat task.wait(0.2) until Players.LocalPlayer lp = Players.LocalPlayer end
local pg = lp:WaitForChild("PlayerGui", 10)

local function contains(s, sub)
    return typeof(s)=="string" and string.find(string.lower(s), string.lower(sub), 1, true) ~= nil
end

-- 找到写着“Trade Requests”的文本控件
local labels = {}
for _, gui in ipairs(pg and pg:GetDescendants() or {}) do
    if gui:IsA("TextLabel") or gui:IsA("TextButton") then
        local t = gui.Text or ""
        if contains(t, "trade") and contains(t, "request") then
            table.insert(labels, gui)
        end
    end
end
print("labels found:", #labels)

-- 在同父级或两层内找按钮，并绑定监听
local function bindButton(btn)
    local path = btn:GetFullName()
    local function logState(tag)
        local txt = btn:IsA("TextButton") and (btn.Text or "") or ""
        print(string.format("[%s] %s type=%s text=%s", tag, path, btn.ClassName, txt))
    end
    if btn.Activated then btn.Activated:Connect(function() logState("Activated") end) end
    if btn.MouseButton1Click then btn.MouseButton1Click:Connect(function() logState("MouseClick") end) end
    if btn.TouchTap then btn.TouchTap:Connect(function() logState("TouchTap") end) end
    print("bound:", path, btn.ClassName)
end

local bound = 0
for _, label in ipairs(labels) do
    local parent = label.Parent
    if parent then
        for _, sib in ipairs(parent:GetChildren()) do
            if sib:IsA("TextButton") or sib:IsA("ImageButton") then
                bindButton(sib); bound += 1
            end
        end
        -- 再向下一层找
        for _, d in ipairs(parent:GetDescendants()) do
            if d ~= label and (d:IsA("TextButton") or d:IsA("ImageButton")) then
                bindButton(d); bound += 1
            end
        end
    end
end
print("buttons bound:", bound)

-- 直接监听服务端远程（若 UI 切换会调它）
local trade = RS:FindFirstChild("Trade")
if trade and trade:FindFirstChild("SetRequestsEnabled") then
    local r = trade.SetRequestsEnabled
    print("SetRequestsEnabled found:", r.ClassName)
else
    warn("SetRequestsEnabled not found under ReplicatedStorage.Trade")
end
print("scan done")